using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Globalization;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Objects : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			this.LoadProducts();
		}
	}
	protected void btnSave_Click(object sender, EventArgs e)
	{
		if (this.Page.IsValid)
		{
			Product prod = new Product();
			prod.Name = txtName.Text;
			prod.Description = txtDescription.Text;

			double result;
			if (Double.TryParse(txtPrice.Text, NumberStyles.Currency, NumberFormatInfo.CurrentInfo, out result))
			{
				prod.Price = result;
			}

			DataAccess.SaveProduct(prod);

			this.LoadProducts();

			alert.SuccessText = "Product saved successfully!";
		}
		else
		{
			alert.HeaderText = "Please correct the following errors:";
		}
	}

	private void LoadProducts()
	{
		grdProducts.DataSource = DataAccess.GetProducts();
		grdProducts.DataBind();
	}
}
